package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.Process;
import com.bonuo.crm.service.ProcessService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

//项目过程Controller
@RestController
@RequestMapping("/crm/process")
@Api(tags = "项目过程管理")
public class ProcessController extends BaseController {
    @Autowired
    private ProcessService processService;

    //查询项目过程
    @GetMapping("/list")
    @ApiOperation(value = "查询项目过程",httpMethod = "GET")
    public TableDataInfo list(Process process,Integer pageNum,Integer pageSize){
        if(pageNum != null && pageSize != null){
            startPage();
        }
        List<Process> processList = processService.selectProcessList(process);
        return getDataTable(processList);
    }


    //添加项目过程
    @PostMapping("/add")
    @ApiOperation(value = "添加项目过程",httpMethod = "POST")
    public AjaxResult add(@RequestBody Process process){
        Integer add = processService.insertProcess(process);
        return toAjax(add);
    }

    //修改项目过程
    @PutMapping("/update")
    @ApiOperation(value = "修改项目过程",httpMethod = "PUT")
    public AjaxResult update(@RequestBody Process process){
        Integer update = processService.updateProcess(process);
        return toAjax(update);
    }

    //删除项目过程
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除项目过程",httpMethod = "DELETE")
    public AjaxResult delete(@PathVariable Integer id){
        Integer delete = processService.deleteProcessById(id);
        return toAjax(delete);
    }

    //导出项目过程
    @PostMapping("/export")
    @ApiOperation(value = "导出项目过程",httpMethod = "POST")
    public void export(HttpServletResponse response,Process process){
        List<Process> processList = processService.selectProcessList(process);
        ExcelUtil<Process> util = new ExcelUtil<Process>(Process.class);
        util.exportExcel(response, processList, "项目过程数据");
    }

}
